package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class JDBCDemo3 {
    public static void main(String[] args) throws Exception{
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root",
                "root"
        );
        Statement statement = connection.createStatement();
        String sql = "INSERT INTO userinfo(username,password,nickname,age) " +
                "VALUE('张三','000000','小三',44) ";
        //增删插入语句DML用专门的executeUpdate()执行更新操作方法
        // 返回一个int值表示所影响记录的条数若为0则更新失败(插入操作应该没有此情况)
        int num = statement.executeUpdate(sql);
        System.out.println(num>0?"执行成功":"执行失败");
        connection.close();
    }
}
